/*
 *  StochasticConcreteNoteTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/10/15.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "StochasticConcreteNoteTester.h"

#include "../../../sc/Tester/CustomAssert.h"
#include "../System0039.h"
#include "../StochasticConcreteNote.h"
#include "../ConcreteNote.h"

namespace sc
{
namespace system0039
{

	void StochasticConcreteNoteTester::TestAll()
	{
		Test_AddNote000();
		Test_AddNote001();
		Test_AddNote002();

		Test_GetConcreteNote000();
		Test_GetConcreteNote001();
		Test_GetConcreteNote002();
	}

	void StochasticConcreteNoteTester::Test_AddNote000()
	{}

	void StochasticConcreteNoteTester::Test_AddNote001()
	{}

	void StochasticConcreteNoteTester::Test_AddNote002()
	{}


	void StochasticConcreteNoteTester::Test_GetConcreteNote000()
	{
		double dynamics = ::sc::Note::piano;
		::sc::hs::Sound::WaveType waveType = ::sc::hs::Sound::SingleSineWave;
		StochasticConcreteNote stochasticNote;
		ConcreteNote note0( waveType, dynamics, ::sc::Note::D4, 1, ::sc::Note::D5, 1 );
		ConcreteNote note1( waveType, dynamics, ::sc::Note::E4, 1, ::sc::Note::F5, 1 );
		stochasticNote.AddNote( note0, 0.5 );
		stochasticNote.AddNote( note1, 0.5 );

		int repeatCount = 10000;
		int countOfNote0 = 0;
		for ( int i = 0; i < repeatCount; i++ )
		{
			ConcreteNote note = stochasticNote.GetConcreteNote();
			if ( note == note0 )
			{
				countOfNote0++;
			}
		}
		AssertLessOrEqual( 0.90 * ( repeatCount / 2.0 ), countOfNote0 );
		AssertLessOrEqual( countOfNote0, 1.10 * ( repeatCount / 2.0 ) );
	}

	void StochasticConcreteNoteTester::Test_GetConcreteNote001()
	{
		double dynamics = ::sc::Note::piano;
		::sc::hs::Sound::WaveType waveType = ::sc::hs::Sound::SingleSineWave;
		StochasticConcreteNote stochasticNote;
		ConcreteNote note0( waveType, dynamics, ::sc::Note::D4, 1, ::sc::Note::D5, 1 );
		ConcreteNote note1( waveType, dynamics, ::sc::Note::E4, 1, ::sc::Note::F5, 1 );
		ConcreteNote note2( waveType, dynamics, ::sc::Note::G4, 1, ::sc::Note::G5, 1 );
		stochasticNote.AddNote( note0, 0.2 );
		stochasticNote.AddNote( note1, 0.2 );
		stochasticNote.AddNote( note2, 0.6 );

		int repeatCount = 10000;
		int countOfNote0 = 0;
		int countOfNote1 = 0;
		int countOfNote2 = 0;
		for ( int i = 0; i < repeatCount; i++ )
		{
			ConcreteNote note = stochasticNote.GetConcreteNote();
			if ( note == note0 )
			{
				countOfNote0++;
			}
			else if ( note == note1 )
			{
				countOfNote1++;
			}
			else if ( note == note2 )
			{
				countOfNote2++;
			}
		}
		AssertLessOrEqual( 0.90 * ( repeatCount / 5.0 ), countOfNote0 );
		AssertLessOrEqual( countOfNote0, 1.10 * ( repeatCount / 5.0 ) );
		AssertLessOrEqual( 0.90 * ( repeatCount / 5.0 ), countOfNote1 );
		AssertLessOrEqual( countOfNote1, 1.10 * ( repeatCount / 5.0 ) );
		AssertLessOrEqual( 0.90 * ( 3.0 * repeatCount / 5.0 ), countOfNote2 );
		AssertLessOrEqual( countOfNote2, 1.10 * ( 3.0 * repeatCount / 5.0 ) );
	}

	void StochasticConcreteNoteTester::Test_GetConcreteNote002()
	{}

}
}
